<?php


namespace Module\DyAi\Admin\Controller;


use Illuminate\Routing\Controller;
use ModStart\Admin\Concern\HasAdminQuickCRUD;
use ModStart\Admin\Layout\AdminCRUDBuilder;
use ModStart\Grid\GridFilter;
use ModStart\Support\Concern\HasFields;
use Module\DyAi\Model\DownContent;
use Module\DyAi\Model\DyAiCategory;

class DownContentController extends Controller
{
    use HasAdminQuickCRUD;

    protected function crud(AdminCRUDBuilder $builder)
    {
        $builder
            ->init(DownContent::class)
            ->field(function ($builder) {
                /** @var HasFields $builder */
                $builder->id('id', 'ID');
                $builder->select('categoryId', '部门')->optionModelTree(DyAiCategory::class);
                $builder->text('title', '名称');
                $builder->image('cover', '封面');
                $builder->textarea('summary', '摘要')->listable(false);
                $builder->json('ai_json', 'ai_json内容')->listable(false);
                $builder->richHtml('content', '内容')->listable(false);
                $builder->display('created_at', L('Created At'))->listable(false);
                $builder->display('updated_at', L('Updated At'))->listable(false);
            })
            ->gridFilter(function (GridFilter $filter) {
                $filter->eq('id', L('ID'));
                $filter->like('title', L('Title'));
                $filter->like('ai_json', L('Ai标签'));
                $filter->eq('categoryId', '部门')->selectModel('dy_ai_category', 'id', 'title');
            })
            ->title('软件列表')
            ->defaultOrder(['sort', 'asc'])
            ->canSort(false);
    }
}
